import $service from '../../../../../service.js';
var user_id,this_;
var log_id;
var user_type = '1';
var doctor_id;
Page({
	data: {
		imgAttay : [],//指定上传图片的集合
		comment_detail : '',
	},
	onLoad(e) {
        console.log(e);
        doctor_id = e.doctor_id;
        log_id = e.log_id;
        wx.setNavigationBarTitle({
            title: '对' + e.doctor_name + '医生评价'
        })
	},
	onShow:function(){
	   
	   user_id = $service.getUserLocalStorage().user_id; 
       if(!$service.isUndefinedAndEmpty($service.getUserLocalStorage().user_type)){
            user_type = $service.getUserLocalStorage().user_type
       }
	},
	inputChange(e) {
		var value = e.detail.value;
        var index = e.currentTarget.dataset.index;
        if(index == 1){
            this.data.comment_detail = value;
        }
		this.setData({
		  comment_detail: this.data.comment_detail
		});
	},
	save:function(){
		if($service.isUndefinedAndEmpty(this.data.comment_detail)){
			wx.showToast({"title":'请输入内容',"icon":"none",duration: 4000});
			return;
		}  
		var json={
			"comment_img": $service.jsonToStr(this.data.imgAttay),
			"comment_detail":this.data.comment_detail,
			"user_id":user_id,
            "log_id" : log_id,
            "user_type" : user_type,
            "doctor_id" : doctor_id
		}
		var jsonAjax = {   
			"url": "userSide_index_addDoctorComment.do", 
			"jsonData": json,
		}
		console.log("意见反馈=="+JSON.stringify(json))
		$service.getAjaxData(jsonAjax,function(jsonObj) {
			wx.showToast({"title":'提交成功',"icon":"none",duration: 4000});
			setTimeout(function(){
				wx.navigateBack({
					delta:1
				})
			},1500);
		});
	},
	// 上传图片
	uploadImg:function(){
		this_ = this;
		if (this_.data.imgAttay.length === 5) { 
			wx.showToast({
				title: '最多上传5张',
				icon:"none",
				duration: 4000
			});
			return;  
		} 
		wx.chooseImage({
			count: 1,          
			success: function (res) {  
				const tempFilePaths = res.tempFilePaths; 
				wx.uploadFile({   
					 url: $service.path_url+'otherFile_fileEntityuploadimg_wx.do', //上传图片需要加图片前缀
					 filePath: tempFilePaths[0],
					 name: 'image',
					 success: (uploadFileRes) => {
					 	var imgObj = {};
					 	imgObj.img = $service.path_url_img+uploadFileRes.data;
					 	this_.data.imgAttay = this_.data.imgAttay.concat(imgObj); 
					 	this_.setData({
					 		imgAttay:this_.data.imgAttay
					 	})
					 },   
				});
			},    
		});
	},  
	// 删除图片
	closeImg:function(e){
		var index = e.currentTarget.dataset.index;
		this.data.imgAttay.splice(index,1);
		this.setData({
			imgAttay:this.data.imgAttay
		})
	} 
})

